Return to doc.sitecore.com

Customizing the Upload Process

Sitecore V5 provides rich built-in applications for working with media files. However, you can change the standard Sitecore behavior in order to enhance or change the way they work.

The file uploading process is defined by pipeline <uiUpload> in the web.config file. Please have a look at the  <processors> section in this file:

<processors>

   <uiUpload>

      <processor mode="on" type="Sitecore.Pipelines.Upload.ResolveFolder, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Unzip, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Done, Sitecore.Kernel" />

   </uiUpload>

</processors>

The list of pipeline processors defines methods called during the upload process, as well as their order.

Each pipeline method receives a set of parameters. The idea behind the pipeline is that one instance of the data object is passed in turn to all processors of the pipeline. Every processor may modify the parameters in a definite way, and the final result is returned from the pipeline.

You can add your custom processor into the pipeline or replace the existing processor with a custom one.  

As an example, we will create a list of files to be uploaded and write it into the log-file before the actual uploading.

Firstly, we should create a custom method (please have a look at the snippet code below)  

public void Process(UploadArgs args)

{

   Sitecore.Diagnostics.Log.Info("The following files should be uploaded:",new Sitecore.Diagnostics.Log());

    foreach (string fileName in args.Files)

    {

       Sitecore.Diagnostics.Log.Info("  " + args.Files[fileName].FileName,new Sitecore.Diagnostics.Log());

    }

}

Then we should add our custom processor to the pipeline:

<uiUpload>

   <processor mode="on" type="Sitecore.Pipelines.Upload.ResolveFolder, Sitecore.Kernel" />

   <processor mode="on" type="CustomUploader.layouts.CustomUpload, CustomUploader" />

   <processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />

   <processor mode="on" type="Sitecore.Pipelines.Upload.Unzip, Sitecore.Kernel" />

   <processor mode="on" type="Sitecore.Pipelines.Upload.Done, Sitecore.Kernel" />

</uiUpload>

As a result, we will see the following entry in the log-file:

2776 11:28:42 INFO  The following files should be uploaded:

2776 11:28:42 INFO    C:\ScreenShots\Overview.JPG

2776 11:28:42 INFO    C:\ScreenShots\ShowAbout.JPG

2776 11:28:42 INFO    C:\ScreenShots\Screenshot - 07_07_2005 , 15_50_18.png

In the same way, one can change the behavior of the upload process in case the file already exists. It is set in the processor

   <processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />

Thus if you want to change this type of behavior, you should replace this processor with the custom one.


Source code for this article

If you want to try this example, you should place the attached DLL file into the /bin folder and modify the <uiUpload> pipeline as described in this article. 

Download source